package com.demo.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description:
 * @author: fanfan
 * @date: 2019/7/10 15:15
 */
@Slf4j
@Component
public class DefaultKafkaProducerCallBack implements KafkaProducerCallBack<String,String> {

    /**
     * @Description: producer发送成功后的业务处理
     * @author: fanfan
     * @param record
     */
    @Override
    public void onSuccess(ProducerRecord<String,String> record) {
        log.info("topic:{},orderId:{},发送成功",record.topic(),record.key());
    }

    /**
     * @Description: producer发送失败后的业务处理
     * @author: fanfan
     * @param record
     * @param e
     */
    @Override
    public void onError(ProducerRecord<String,String> record, Exception e) {
        log.info("topic:{},orderId:{},发送失败",record.topic(),record.key());
    }

    private static String getInNetIp(){
        String ip = null;
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e1) {
            e1.printStackTrace();
        }
        return ip;
    }
}
